import { _decorator, Component, Node, ProgressBar, Animation, Label, labelAssembler, EventTouch, director, Sprite, SpriteFrame } from 'cc';
import { GameManager } from '../GameManager';
import { GameUtil } from '../GameUtil';
import { BundleManager } from '../../AshFramework/Managers/BundleManager';
import { TreasureBox } from '../TreasureBox';
import { WeaponManager } from '../WeaponManager';
const { ccclass, property } = _decorator;

@ccclass('BattleWindow')
export class BattleWindow extends Component {

    @property(Sprite)
    BGSprite: Sprite = null;

    @property(ProgressBar)
    TreasureProgress: ProgressBar = null;

    @property(Node)
    PreNode: Node = null;

    @property(Node)
    NextNode: Node = null;

    @property([Node])
    TreasureBoxs: Node[] = [];


    startBtn(event: EventTouch, customEventData: any) {
        //加载场景
        WeaponManager.Instance.reinitialize();
        director.loadScene("Battle");
    }

    initBG() {
        this.BGSprite.spriteFrame = BundleManager.AssetMap.get(GameManager.Instance.userData.lv) as SpriteFrame;
        this.showTreasureBox();
    }

    //上一关
    lastBtn() {
        GameUtil.showHint(`返回上一关`);
    }

    //下一关
    nextBtn() {
        GameUtil.showHint(`下一关`);
    }

    showTreasureBox() {
        for (let i = 0; i <= this.TreasureBoxs.length; i++) {
            if (this.TreasureBoxs[i]) {
                this.TreasureBoxs[i].getComponent(TreasureBox).init();
            }
        }
    }

    protected onEnable(): void {
        this.initBG();
    }
}


